<?php
namespace app\growthArchives\controller;
use app\common\Base;
use think\Db;

class PrepareArchives extends Base {
	
	public function index() {
		return $this->fetch();
	}

	public function pageQuery() {
		$where = [];
		$termId = input("termId");
		$grade = input("grade");
		$subjectId = input("subjectId");
		$depart = input("depart");
		$commentType = input("commentType");
		$teacherName = input("teacherName");
		$startDate = input("startDate");
		$endDate = input("endDate");
		$page = input("page");
		$rows = input("rows");
		if($termId) $where["学期ID"] = $termId;
		if($grade) $where["年级号"] = $grade;
		if($subjectId) $where["任教学科ID"] = $subjectId;
		if($depart) $where["评价部门"] = $depart;
		if($commentType) $where["评价类别"] = $commentType;
		if($teacherName) $where["姓名"] = array("like",$teacherName);
		if($startDate) $where["评价日期"] = array("egt", $startDate);
		if($endDate) $where["评价日期"] = array("elt", $endDate);
		$result = Db::table('教师常规')->alias('a')
				  ->join('学期名称 b','a.学期ID=b.ID','LEFT')
				  ->join('教师信息 c','a.教师ID=c.ID','LEFT')
				  ->field("a.ID,a.评价部门,a.评价类别,a.评价日期,a.教师ID,a.评价内容,a.加减分,a.学期ID,b.学期名称,c.姓名")
				  ->where($where)
				  ->order("ID desc")
				  ->page($page, $rows)
		          ->select();
		$count = Db::table('教师常规')->alias('a')
				  ->join('教师信息 c','a.教师ID=c.ID','LEFT')
				  ->where($where)
				  ->count();
		$grid['rows'] = selectResult($result);
        $grid['total'] = $count;
		return $grid;
	}

}
